<%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!-- public quote -->
<%@include file="/jsp/comm_css_include.jsp"%>
<link rel="stylesheet" type="text/css" href="${basePath}/css/zTreeStyle/zTreeStyle/zTreeStyle.css">
<!doctype html>
<html>
<head>
</head>
<body class="gray-bg">
<div class="container creditbody">
		 <div class="iboxtitle">
		 	<span><i class="glyphicon glyphicon-map-marker"></i>&nbsp;鑫合汇>计划还款</span>
         </div>
         <div class="buttonfixed">
	       <button type="button" id="save_button" style="display:none;" class="btn dpbtn_blue btnaplly" onclick="saveorupdate();">保存提交</button>
	       <button type="button" id="update_button" style="display:none;" class="btn dpbtn_blue btnaplly" onclick="saveorupdate();">修改提交</button>
	    </div>
         <div class="ibox-content ibox-con">
			<form class="form-horizontal" id="commentForm">
			<%@include file="/jsp/comm_yw_info_include.jsp"%>
			<div class="business-manwife">还款信息</div>			
			<div class="padding-nono">
			    <table cellpadding="0" cellspacing="0" border="0" class="buyinfor-table">
						<tr>
							<td align="right">
								<label class="control-label np">待还金额：</label>
							</td>
							<td>
								<input  class="form-control" type="input" id="actualRaiseFee" name="actualRaiseFee" readonly="readonly" />
							</td>
							<td align="right">
								<label class="control-label np">计划还款时间：</label>
							</td>
							<td>
								<input  class="form-control" type="input" id="borrowerRepayDate" name="borrowerRepayDate" readonly="readonly" />
							</td>
						</tr>
						<tr>	
							<td align="right">
								<label class="control-label np">还款时间：</label>
							</td>
							<td>
								<input  class="laydate-icon form-control" type="text" id="dateRepayment" name="dateRepayment" placeholder="还款时间(必填)" onclick="laydate();" />
							</td>
							<td style="padding-top: 15px;" colspan="2" id="huankuanState">
							</td>
						</tr>
						
						<tr>	
							<td align="right">
								<label class="control-label np">还款金额：</label>
							</td>
							<td>
								<input  class="form-control" type="number" id="amountRepaymen" name="amountRepaymen" placeholder="还款金额(必填)"/>
							</td>
						</tr>
						
						<tr>	
							<td align="right">
								<label class="control-label np">还款账户：</label>
							</td>
							<td  colspan="3">
								<select  class="form-control"  id="thAccountRepaymen" name="thAccountRepaymen"  required="required"></select>
							</td>
						</tr>
						
						<tr>
							<td align="right">
								<label class="control-label np">财务审核人：</label>
							</td>
							<td>
								<input  class="form-control" type="text" id="nameAuditor" name="nameAuditor" placeholder="财务审核人" />
							</td>
							<td align="right">
								<label class="control-label np">财务审核时间：</label>
							</td>
							<td>
								<input  class="laydate-icon form-control"  type="text" id="timeAudit" name="timeAudit" placeholder="财务审核时间" onclick="laydate();" />
							</td>
						</tr>
						
						<tr>
							<td align="right">
								<label class="control-label np">财务档案编号：</label>
							</td>
							<td>
								<input  class="form-control" type="text" id="financialRecordsNumber" name="financialRecordsNumber" placeholder="财务档案编号" />
							</td>
						</tr>
					</table>	
					<input type="hidden" id="hkId"/>
<!-- 					<input type="hidden" id="id"/> -->
			</div>
			<div class="business-manwife clear-both">经办信息</div>
			<div class="padding-nono">
				<table cellpadding="0" cellspacing="0" border="0" class="buyinfor-table">
					<tr>
						<td align="right"><label class="control-label np">经办人：</label></td>
						<td><input class="form-control" type="text" value="${current_user_key.uname }" readonly="readonly" /></td>
						<td align="right"><label class="control-label np">经办时间：</label>
						</td>
						<td><input readonly="readonly" value="" class="form-control" id="laydateNow" /></td>
					</tr>
				</table>
			</div>
		</form>
	</div>
</div>	
	
	<!-- public quote -->
    <%@include file="/jsp/comm_js_include.jsp"%>
 	
 	<!-- layerDate plugin javascript -->
    <script type="text/javascript" src="${basePath}/js/plugins/layer/laydate/laydate.js"></script>

    <script type="text/javascript">
	    jQuery(function($) {  
	    	$("#borrowerRepayDate").val($.getUrlData("borrowerRepayDate"));
	    	$("#actualRaiseFee").val($.getUrlData("actualRaiseFee"));
	    	$('#laydateNow').val(laydate.now());
	    	getthrepaymentType();
	    });
		
	   function getthrepaymentType(){
			$.dpAjax({
				show:false,
		    	url:'${basePath}/DataDictionaryController/getEnableList',
	 			data:{
	 				"parentValue":"TH_Repayment_Type"
	 			},
	 			success: function(datas){
	 				var result = datas.result.rows;
					var html='';
				    for(var i=0;i<result.length;i++){
				    	 var programme = result[i];
				    	 html +='&nbsp;<label><input type="radio" name="thRepaymentType" value="'+programme.value+'" />'+programme.name+'</label>&nbsp;'; 
				      }
				     $("#huankuanState").html(html);
				     getData();
					 return;
	            }
		    });
		 }
	    
	    function getData(){
	    	var data={};
 	 		data.busiId=$.getUrlData("busiId");
 	 		$.dpAjax({
 	 			show:false,
 	    		url:'${basePath}/ThRepaymentController/list',
 	    		data:data,
 				success: function(datas){
 					  var data=datas.result.rows;
	   				  if(data.length>0){
	   					  $("#save_button").hide();
	   					  $("#update_button").show();
	   					  $("#hkId").val(data[0].replaceId);
	   					  var thRepaymentType = data[0].thRepaymentType;
	   					  if(thRepaymentType && thRepaymentType!=""){
		   					  $("input[name='thRepaymentType']:radio[value='"+thRepaymentType+"']").attr('checked','true');
	   					  }
	   					  $("#dateRepayment").val(data[0].dateRepayment);
	   					  $("#amountRepaymen").val(data[0].amountRepaymen);
	   					  $("#thAccountRepaymen").val(data[0].thAccountRepaymen);
	   					  $("#nameAuditor").val(data[0].nameAuditor);
	   					  $("#timeAudit").val(data[0].timeAudit);
	   					  $("#financialRecordsNumber").val(data[0].financialRecordsNumber);
	   				  }else{
	   					  $("#update_button").hide();
	   					  $("#save_button").show();
	   				  }
						  layer.msg('执行成功！', {icon: 6});
						  return;
	 	            }
 	    	});
 	    }
	    
	    $(function(){
			$.dpAjax({
				show:false,
		    	url:'${basePath}/DataDictionaryController/getEnableList',
	 			data:{
	 				"parentValue":"TH_Repayment_Account",
	 				"addedValue1":"xhh"
	 			},
	 			success: function(datas){
	 				 var result = datas.result.rows;
					 var programmeSel='<option value="">请选择</option>';
				     for(var i=0;i<result.length;i++){
				          var programme = result[i];
				          programmeSel +='<option value="'+programme.value+'">'+programme.name+'</option>';
				     }
				     $("#thAccountRepaymen").html(programmeSel);
					 return;
	              }
		    	});
		 });
	    
	    $(function(){
	        $("#commentForm").validate({
	            rules: {
	            	amountRepaymen:{
	            		allMoney: true,
	            	}
	            },
	            //重写showErrors
	            showErrors: function (errorMap, errorList) {
	                
	                $.each(errorList, function (i, v) {
	                    layer.tips(v.message, v.element, { time: 1500 });
	                    return false;
	                });  
	            },
	            /* 失去焦点时验证 */
	            onfocusout: function(element) { $(element).valid(); },
	            /*  键盘抬起不验证 */
	            onkeyup:false,
	        });
		});
	    
		//确认
		function saveorupdate(){
			var validstatus = $("#commentForm").valid();
			if(validstatus){
				var data={};
				var url='${basePath}/ThRepaymentController/insert';
				var hkId=$("#hkId").val();
				if(hkId!=""){
					url='${basePath}/ThRepaymentController/modify';
					data.id=hkId;
				}
				data.thRepaymentType=$("input[name='thRepaymentType']:checked").val();
				data.dateRepayment=$("#dateRepayment").val();
				data.amountRepaymen=$("#amountRepaymen").val();
				data.thAccountRepaymen=$("#thAccountRepaymen").val();
				data.nameAuditor=$("#nameAuditor").val();
				data.timeAudit=$("#timeAudit").val();
				data.financialRecordsNumber=$("#financialRecordsNumber").val();
				data.busiId=$.getUrlData("busiId");
				$.dpAjax({
		    		url:url,
		    		data:data,
					success: function(datas){
						layer.msg('执行成功！', {icon: 6});
//		    			saveIndex = 1;
//		    			window.location.href="${basePath}/web/caiWuXiangGuan/diankuanZBList.jsp";
		    			return ;
		            }
		    	});
			}else{
				 layer.msg('有验证未通过，请仔细检查！', {icon: 5});
			}
		}
    </script>
</body>
</html>
